package jp.co.kayo.android.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class SampleMain extends Activity {
	ViewFlipper flipper;
	float pointx;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		TextView tx1 = (TextView) findViewById(R.id.TextView01);
		TextView tx2 = (TextView) findViewById(R.id.TextView02);
		TextView tx3 = (TextView) findViewById(R.id.TextView03);

		setTextView(tx1, 10);
		setTextView(tx2, 9);
		setTextView(tx3, 60);

		flipper = (ViewFlipper) findViewById(R.id.ViewFlipper01);

		flipper.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
				case MotionEvent.ACTION_DOWN:
					pointx = event.getX();
					break;
				case MotionEvent.ACTION_UP:
					float x = event.getX();
					if (pointx < x) {
						flipper.showNext();
					}
					if (pointx > x) {
						flipper.showPrevious();
					}
					break;
				}
				return true;
			}
		});
	}

	private void setTextView(TextView view, int n) {
		StringBuilder buf = new StringBuilder();
		for (int i = 0; i < n; i++) {
			buf.append("text").append(i).append("\n");
		}
		view.setText(buf.toString());
	}
}